package com.q.tqb.view.dialog;


import android.app.Activity;
import android.app.Dialog;
import android.graphics.Point;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.jungly.gridpasswordview.GridPasswordView;
import com.q.tqb.R;
import com.q.tqb.activity.send.SendSpeakingActivity;
import com.q.tqb.util.DensityUtil;
import com.q.tqb.util.KeyboardUtils;


public class PayPassDialog extends Dialog {


    private Activity mActivity;
    private double allMoney;
    private int type;
    private GridPasswordView mGridPasswordView;

    public PayPassDialog(Activity activity, double allMoney, int type) {
        super(activity, R.style.myDialog);
        this.mActivity = activity;
        this.allMoney = allMoney;
        this.type = type;
        initLoginDialog();
    }

    private void initLoginDialog() {

        KeyboardUtils.showSoftInput(mActivity);

        View v = View.inflate(mActivity, R.layout.dialog_pay_pass, null);
        TextView tvMoney = v.findViewById(R.id.tv_money);
        TextView tvType = v.findViewById(R.id.tv_type);
        TextView tvPay = v.findViewById(R.id.tv_pay);
        mGridPasswordView = v.findViewById(R.id.pswView);

        tvMoney.setText(allMoney + "");

        if (type == 2) {
            tvType.setText("提现");
            tvPay.setText("确认提现");
        }
        mGridPasswordView.setOnPasswordChangedListener(new GridPasswordView.OnPasswordChangedListener() {
            @Override
            public void onTextChanged(String psw) {

            }

            @Override
            public void onInputFinish(String psw) {
                dismiss();
                mCommonListener.onClick(psw);
            }
        });

        Point size = new Point();
        mActivity.getWindowManager().getDefaultDisplay().getSize(size);
        int height = DensityUtil.dip2px(mActivity, 240);
        int width = (int) (size.x * 0.8);


        LinearLayout.LayoutParams linearParams = (LinearLayout.LayoutParams) mGridPasswordView.getLayoutParams();
        linearParams.height = (width - DensityUtil.dip2px(mActivity, 20)) / 6;
        mGridPasswordView.setLayoutParams(linearParams);

        setContentView(v);
        Window dialogWindow = getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        dialogWindow.setGravity(Gravity.CENTER);
        lp.height = height;
        lp.width = width;
        dialogWindow.setAttributes(lp);


    }


    public interface CommonListener {
        void onClick(String pass);
    }

    private CommonListener mCommonListener;

    public void setOnSettingListener(CommonListener listener) {
        this.mCommonListener = listener;
    }


}
